package com.ysl.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.util.Properties;

//druid的连接池工具类
public class DruidManager {
    //定义DataSource对象 - java管理连接池
    private static DataSource dataSource = null;

    static {
        //创建Properties类的对象，用来操作.properties配置文件
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream("C:\\Users\\星星在唱歌\\Desktop\\学习\\LIU\\U3-day02-demo\\src\\main\\resources\\druid.properties"));
            //通过druid的工厂类来创建DataSource对象
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //获取DataSource对象
    public static DataSource getDataSource() {
        return dataSource;
    }

    public static void main(String[] args) {
        DataSource dataSource = DruidManager.getDataSource();
        System.out.println("dataSource = " + dataSource);
    }
}
